package com.youhong.teethcare;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

import com.youhong.teethcare.services.Common;
import com.youhong.teethcare.utils.AppManager;

public class StartPageActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        final View view = View.inflate(this, R.layout.activity_start_page, null);
        AppManager.getInstance().addActivity(this);
        setContentView(view);

        //渐变展示启动屏
        AlphaAnimation aa = new AlphaAnimation(0.1f, 1.0f);
        aa.setDuration(2000);
        view.startAnimation(aa);
        aa.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation arg0) {
                runnable_start.run();

            }

            @Override
            public void onAnimationRepeat(Animation animation) {


            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

        });
    }

    Runnable runnable_start = new Runnable() {

        @Override
        public void run() {
            if (Common.userInfo.isFirstTimeIntoAPP() == false) {

                Intent intent = new Intent(getApplicationContext(), BannerActivity.class);
                startActivity(intent);

            } else {

                if (TextUtils.isEmpty(Common.userInfo.getToken())) {

                    Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                    startActivity(intent);

                } else {

                    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(intent);

                }

            }
            finish();
        }
    };
}
